package net.jsoft.pms.repository.problem;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import net.jsoft.pms.entity.problem.ProblemTask;

@Transactional
public interface ProblemRepository extends JpaSpecificationExecutor<ProblemTask>, PagingAndSortingRepository<ProblemTask, Long>
{

    @Query("from ProblemTask where status = :status")
    List<ProblemTask> findAllByStatus(@Param("status") String status);

    //某一个时间段内的问题
    @Query(value = " select * from(select * from t_dzswj_problem where ( dealDate between :begin and :end and status = '0') union all select * from t_dzswj_problem where status = '1' and insertDate <= :end union all select * from t_dzswj_problem where ( dealDate > :end and status = '0' and   insertDate <= :end  ) ) t;", nativeQuery = true)
    List<ProblemTask> findAllByDates(@Param("begin") Date begin, @Param("end") Date end);
    //    @Modifying

    @Query("from ProblemTask where id = :id")
    ProblemTask findById(@Param("id") String id);

    @Query(value = "select * from  t_dzswj_problem where status = '1' and id not in (select problemId from t_dzswj_plan where problemId is not null)", nativeQuery = true)
    List<ProblemTask> findNoTaskProblems();

}
